var  app = getApp();
var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');

Page({
  data: {
    is_distributor:1,
    total_price: 0,
    price: 0,
    cash_price: 0,
    draw_num: 0,
    team_count: 0,
    order_num: 0,
    frozen_amount:0,
    team_count:0,
    userInfo: {
      nickName: '点击登录',
      avatarUrl: '/images/more/unlogin.png'
    }, 
    referee:{}
  },
  onLoad: function (t) {
    this.getList();
  },
  onReady: function () { },
  onShow: function () {
    this.getList();
  },
  onHide: function () { },
  onUnload: function () { },
  onPullDownRefresh: function () { },
  onReachBottom: function () { },
  wornin: function(){
    wx.showToast({ title: '功能开发中，敬请期待', icon: 'none', 
    duration: 3000,mask: false }) 
 
  },
  getList: function () {
    var a = this;
    //获取用户的登录信息
    if (app.globalData.hasLogin) {
      let userInfo = wx.getStorageSync('userInfo');
      a.setData({
        userInfo: userInfo,
      });
    }
    util.request(api.distributionCenter).then(function (res) {
      if (res.errno == 0) {
        a.setData({
          total_price: res.data.amount.totalAmount == null ? 0 : res.data.amount.totalAmount,
          //可提现
          price: res.data.amount.avaibleAmount == null ? 0 : res.data.amount.avaibleAmount,
          //已提现
          cash_price: res.data.amount.withdrawAmount == null ? 0 : res.data.amount.withdrawAmount,
          //提现明细
          draw_num: res.data.drawCount == null ? 0 : res.data.drawCount,
          //待结算的
          frozen_amount: res.data.amount.frozenAmount == null ? 0 : res.data.amount.frozenAmount,
          //下线
          team_count: res.data.memCount == null ? 0 : res.data.memCount,
          //订单
          order_num: res.data.frofitCount == null ? 0 : res.data.frofitCount,
          referee: res.data.referee,

        })
      }
    });
  },
  more: function () {
    wx.showToast({
      title: '更多功能，敬请期待...', icon: 'none',
      duration: 3000, mask: false
    })
  },
  main: function () {
    wx.switchTab({ url: '/pages/index/index' });
  },
  getPermission: function () {
    this.showModal();

    // wx.showModal({
    //   title: '提示',
    //   content: '购买任意产品自动获取分销资格，其他途径购买可联系客服获取分销资格。通过分享小程序给其他用户获取佣金。',
    //   showCancel: false
    // });

  },
  openCashPage: function () {
    var a = this;
    util.request(api.isMember).then(function (res) {
      console.log(res.data === true);
      if (res.errno == 0 && res.data===true) {
        wx.navigateTo({ url: '/pages/ucenter/cash/cash' });
      }else{
        wx.showToast({
          title: '您还不是分销商。购买任意产品便可享受分销商权益！', icon: 'none',
          duration: 3000, mask: false
        }) 
      }
    });
  },


  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  onPullDownRefresh: function () {
    this.getList();
  }
});